package com.raymond.queue.client.codec.decoding;

import com.raymond.queue.common.codec.annotation.MsgCodec;
import com.raymond.queue.common.codec.decoding.BaseDecoder;
import com.raymond.queue.common.enums.CommandIdType;
import com.raymond.queue.common.msg.BaseAgreement;
import com.raymond.queue.common.msg.response.CreateTopicResponse;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

/**
 * 创建topic响应解码
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-07-14 15:13
 */
@MsgCodec(commandId = CommandIdType.CREATE_TOPIC_RESP)
public class CreateTopicResponseDecoder extends BaseDecoder {

    @Override
    public void decode(ChannelHandlerContext ctx, BaseAgreement msg, List<Object> out) throws Exception {
        ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
        out.add(new CreateTopicResponse(bodyBuffer.readInt(), msg.getSequenceId()));
    }
}
